﻿using AutoMapper;
using MediatR;
using MyMES.Domain.zyy;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.Requisitions;

namespace MyMES.Writer.API.Application.CommendHandlers.Requisitions
{
    public class UpdateRequisitionsHandler : IRequestHandler<UpdateRequisitionCommand, APIResult<Requisition>>
    {
        private readonly IMapper mapper;
        private readonly IBaseRepository<Requisition> repository;

        public UpdateRequisitionsHandler(IMapper mapper,IBaseRepository<Requisition> repository)
        {
            this.mapper = mapper;
            this.repository = repository;
        }
        public async Task<APIResult<Requisition>> Handle(UpdateRequisitionCommand request, CancellationToken cancellationToken)
        {
            APIResult<Requisition> rusult = new APIResult<Requisition>();
            rusult.Code = APIEnum.修改成功;
            rusult.Msg = "修改成功";
            var model = mapper.Map<Requisition>(request);
            string aa = "update Requisition set  RequisitionNum=@RequisitionNum,RequisitionName=@RequisitionName,RequisitionOrder=@RequisitionOrder,Workstation=@Workstation,CustomerId=@CustomerId,Customer_name=@Customer_name ,CustomerTime=@CustomerTime ,Documentstatus=@Documentstatus  where Requisitionid = @Requisitionid";
            await repository.Update(model, aa);
            return rusult;
        }
    }
}
